﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using Microsoft.Phone.Reactive;

namespace Sample.Views
{
    public partial class Clock : PhoneApplicationPage
    {
        private IDisposable _disposer = null;

        public Clock()
        {
            InitializeComponent();
        }

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            _disposer = Observable.Timer(TimeSpan.FromSeconds(0), TimeSpan.FromSeconds(1))
                .ObserveOnDispatcher()
                .Subscribe(value =>
                {
                    Hour.Index = DateTime.Now.Hour;
                    Minute.Index = DateTime.Now.Minute;
                    Second.Index = DateTime.Now.Second;
                });
        }

        private void Hour_IndexChanged(object sender, RingControls.IndexChangedEventArgs args)
        {
            Hour.Content = args.Index;
        }

        private void Minute_IndexChanged(object sender, RingControls.IndexChangedEventArgs args)
        {
            Minute.Content = args.Index;
        }

        private void Second_IndexChanged(object sender, RingControls.IndexChangedEventArgs args)
        {
            Second.Content = args.Index;
        }
    }
}